﻿using System;
using System.Collections.Generic;
using System.Text;
using AspNetCs.SQLServerDAL;
using AspNetCs.Model;
using AspNetCs.IDAL;
using AspNetCs.DALFactory;
using AspNetCs.Enumerations;
using System.Data;
using AspNetCs.Enumerations.Channel_Enum;
using AspNetCs.SQLServerDAL;


namespace AspNetCs.Bll
{
    public class Article
    {
        IArticle art = Conn.CreateArticle();

        //添加文章
        public bool AddArticle(Article_Model model)
        {
            return art.AddArticle(model) > 0 ? true : false;
        }

        //修改文章
        public bool UpdateArticle(Article_Model model)
        {
            return art.UpdateArticle(model) > 0 ? true : false;
        }

        //通过文章编号获得文章详细
        public Article_Model getArticleModelByArticleID(int ArticleID)
        {
            return art.getArticleModelByArticleID(ArticleID); 
        }

        public bool DeleteArticle(int ArticleID)
        {
            return art.DeleteArticle(ArticleID) > 0 ? true : false;
        }

        /// <summary>
        /// 删除文章(物理删除)
        /// </summary>
        /// <param name="ArticleID"></param>
        /// <returns></returns>
        public int PhyicDeleteArticle(int ArticleID)
        {
            return art.PhyicDeleteArticle(ArticleID);
        }

        public bool CheckArticle(int ArticleID)
        {
            return art.CheckArticle(ArticleID) > 0 ? true : false ; 
        }

        public bool RebackArticle(int ArticleID)
        {
            return art.RebackArticle(ArticleID) > 0 ? true : false;
        }


        public bool RebackAllArticle()
        {
            return art.RebackAllArticle() > 0 ? true : false;
        }
        /// <summary>
        /// 获得各种不同类型的文章
        /// </summary>
        /// <param name="queryPropertys">要查询的字段(Example:"id,name,user_name"),查询所有字段用"*"</param>
        /// <param name="IsMaster">是否是管理员</param>
        /// <param name="EditorId">发布者编号</param>
        /// <param name="ChannelTypeID">频道类型id(如公墓id、纪念馆id)</param>
        /// <param name="channelType">文章类型用枚举值Channel_Type表示(如公墓、纪念馆)</param>
        /// <returns></returns>
        public DataTable getKindsOfArticle(string queryPropertys, int IsMaster, int EditorId, int ChannelTypeID, Channel_Type channelType, int ClassId)
        {
            return art.getKindsOfArticle(queryPropertys, IsMaster, EditorId, ChannelTypeID, channelType,ClassId);
        
        }

        /// <summary>
        /// 设置或者取消置顶
        /// </summary>
        /// <param name="ArticleId">文章编号</param>
        /// <param name="SubmitOrCancle">0:取消置顶 1:设置置顶</param>
        /// <returns></returns>
        public int SetTop(int ArticleId, int SubmitOrCancle)
        {
            return art.SetTop(ArticleId,SubmitOrCancle);
        }

        /// <summary>
        /// 设置或者取消推荐
        /// </summary>
        /// <param name="ArticleId">文章编号</param>
        /// <param name="SubmitOrCancle">0:取消推荐 1:设置推荐</param>
        /// <returns></returns>
        public int SetCommend(int ArticleId, int SubmitOrCancle)
        {
            return art.SetCommend(ArticleId,SubmitOrCancle);
        }


        /// <summary>
        /// 设置或者取消热点
        /// </summary>
        /// <param name="ArticleId">文章编号</param>
        /// <param name="SubmitOrCancle">0:取消热点 1:设置热点</param>
        /// <returns></returns>
        public int SetHot(int ArticleId, int SubmitOrCancle)
        {
            return art.SetHot(ArticleId,SubmitOrCancle);
        }


        /// <summary>
        /// 设置或者取消审核
        /// </summary>
        /// <param name="ArticleId">文章编号</param>
        /// <param name="SubmitOrCancle">0:取消审核 1:设置审核</param>
        /// <returns></returns>
        public int SetCheck(int ArticleId, int SubmitOrCancle)
        {
            return art.SetCheck(ArticleId, SubmitOrCancle);
        }

        /// <summary>
        /// 下一条
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable nextItem(int id)
        {
            DataTable dataTable = new DataTable();
            string cmdText = "select top 1 *from Article where ArticleId<{0} order by ArticleId desc";
            cmdText = string.Format(cmdText,id);
            db dbclass = new db();
            dataTable = dbclass.GetSql_DataTable(cmdText);
            return dataTable;
        }

        /// <summary>
        /// 上一条
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable preItem(int id)
        {
            DataTable dataTable = new DataTable();
            string cmdText = "select top 1 *from Article where ArticleId>{0} order by ArticleId asc";
            cmdText = string.Format(cmdText,id);
            db dbclass = new db();
            dataTable = dbclass.GetSql_DataTable(cmdText);
            return dataTable;
        }

    }
}
